import VectorLayer from "ol/layer/Vector"
import VectorSource from "ol/source/Vector"
import layerMethods from '../layer/index'
import Draw, { createBox, createRegularPolygon } from 'ol/interaction/Draw'

const drawLayer = layerMethods.addVectorLayer({ zIndex: 20 })

/**
 * 
 * @param {*} type 绘制类型 Point, lineString, Polygon, Circle, Rectangle,Square
 * @returns 
 */
export function draw (type = 'Rectangle') {
  let geometryFunction
  if (type === 'Rectangle') {
    type = 'Circle'
    geometryFunction = createBox()
  } else if (type == "Square") {
    type = 'Circle'
    geometryFunction = createRegularPolygon(4)
  }
  const draw = new Draw({
    source: drawLayer.getSource(),
    type,
    geometryFunction,
    // style: new Style({
    //   fill: new Fill({
    //     color: "rgba(255, 255, 255, 0.2)",
    //   }),
    //   stroke: new Stroke({
    //     color: "#ffcc33",
    //     width: 2,
    //   }),
    //   image: new Circle({
    //     radius: 7,
    //     fill: new Fill({
    //       color: "#ffcc33",
    //     }),
    //   }),
    // }),
  })
  return {
    draw,
    drawLayer
  }
}